package org.easy.tool.controller;

import org.easy.tool.common.R;
import org.easy.tool.service.BackupService;
import org.easy.tool.service.IAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.file.Path;
import java.util.LinkedHashMap;

/**
 * @author Valley
 * @since 2025-03-27 09:09:15
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    IAdmin adminService;

    @Autowired
    BackupService backupService;


    @RequestMapping("addAdmin")
    public R addAdmin(@RequestBody(required = false)LinkedHashMap data) throws Exception {
        boolean status = adminService.addAdmin(data);
        return R.ok(status);
    }

    @RequestMapping("backup")
    public R backup(@RequestBody(required = false)LinkedHashMap data) throws Exception {
        Path backup = backupService.backup();
        return R.ok("备份成功:"+backup.getFileName());
    }



}
